package com.lorenzogao.pley.ui.adapter

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import com.lorenzogao.pley.bean.FragmentInfo
import com.lorenzogao.pley.ui.fragment.CategoryFragment
import com.lorenzogao.pley.ui.fragment.GamesFragment
import com.lorenzogao.pley.ui.fragment.TopListFragment
import com.lorenzogao.pley.ui.fragment.RecommendFragment
import java.util.*

/**
 * 作者：Lorenzo Gao
 * Date: 2017/12/22
 * Time: 16:17
 * 邮箱：2508719070@qq.com
 * Description:
 */

class ViewPagerAdapter(fm: FragmentManager): FragmentStatePagerAdapter(fm) {


    var mFragments = ArrayList<FragmentInfo>(4)



    init {
        initFragments()

    }

    private fun initFragments() {
        mFragments.add(FragmentInfo("推荐",RecommendFragment()))
        mFragments.add(FragmentInfo("排行", TopListFragment()))
        mFragments.add(FragmentInfo("游戏",GamesFragment()))
        mFragments.add(FragmentInfo("分类",CategoryFragment()))
    }

    override fun getPageTitle(position: Int): CharSequence {
        return mFragments.get(position).title
    }

    override fun getItem(position: Int): Fragment? {
        var fragment: Fragment? = null

        fragment=mFragments.get(position).fragment
       /* when (position) {
            0 -> fragment = RecommendFragment()
            1 -> fragment = TopListFragment()
            2 -> fragment = GamesFragment()
            3 -> fragment = CategoryFragment()
        }*/

        return fragment
    }

    override fun getCount(): Int {

        return mFragments.size
    }


}